package com.cskaoyan.javase.homework.day15;

/**
 * @description:
 * @author: 景天
 * @date: 2022/2/10 17:34
 **/

/*
"peter piper picked a peck of pickled peppers"
统计这段绕口令有多少个以p开头的单词
 */
public class Work1 {
    public static void main(String[] args) {
        String s = "peter piper picked a peck of pickled peppers";
        // 以" "分隔成字符串数组
        String[] strs = s.split(" ");
        int count = 0;
        // 遍历字符串数组,以p开头 计数器+1
        for (String str :
                strs) {
            if (str.startsWith("p")) {
                count += 1;
            }
        }
        System.out.println("p开头的单词有:" + count);
    }
}
